package com.kgc.scd.controller;

import com.kgc.scd.util.PageSupport;
import com.kgc.scd.vo.ShopGoodsVO;
import com.kgc.scd.vo.ShopHistoryWordsVO;
import com.kgc.scd.service.GoodsService;
import com.kgc.scd.service.HistoryService;
import com.kgc.scd.service.SensitiveWordService;
import com.kgc.scd.vo.SensitiveWord;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页搜索功能控制类
 */
@RestController
@Slf4j
public class GoodsController {
        @Autowired
        private GoodsService goodsService;

        @Autowired
        private HistoryService historyService;

        @Autowired
        private SensitiveWordService sensitiveWordService;
    /**
     * 首页搜索
     * @param pageNo
     * @param pageSize
     * @param words
     * @return
     */
         @GetMapping("/goods")
        public PageSupport<ShopGoodsVO> Goods(@RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                              @RequestParam(name = "pageSize", required = false, defaultValue = "3") Integer pageSize,
                                              @RequestParam(name = "words", required = false) String words) {


             PageSupport<ShopGoodsVO> shopGoodsPageList=goodsService.PageList(words, pageNo, pageSize);

                return shopGoodsPageList;

    }

    /**
     * 存储历史数据
     * @return
     */
    @PostMapping("/history")
    public int HistoryWords(@RequestBody ShopHistoryWordsVO shopHistoryWordsVO) {
        return historyService.intsert(shopHistoryWordsVO);
    }

    /**
     * 查询历史记录列表
     * @return
     */
    @GetMapping("/historylist")
    public  List<ShopHistoryWordsVO> lsit(){
        return historyService.getHistoryWords();
    }

    /**
     * 查询敏感字列表
     * @return
     */
    @GetMapping("/sendWord")
    public  List<SensitiveWord>sendWordSend(){
        return sensitiveWordService.getSensitiveWords();
    }


    /**
     * 删除历史记录，根据·一个·或者多个
     * @param
     * @return
     */
    @GetMapping("/hiDelete")
    public boolean hisDelete(@RequestParam List<String> words){
       return  historyService.delete(words);
    }

}
